[root@localhost opt]# cat sqoop_inp_g.sh
#!/bin/bash
if [  $# -lt 1 ] ; then
    echo "参数不合规";
    echo "全量参数：1-oracle表名，2-hive目标数据库名，3-Oracle用户名，4-ALL";
    echo "增量参数：1-oracle表名，2-hive目标数据库名，3-Oracle用户名，4-ADD，5-用于增量的列名，6-上次导入的最大值";

fi


TBNAME=${1^^};
HIVEDB=$2;
DB_URL='jdbc:oracle:thin:@192.168.159.1:1521/ORCL'
DB_USER=$3;
DB_PASSWORD='123456';

DELDIR="hdfs dfs -rm -r /user/root/$TBNAME";
$DELDIR




if [ $4 == 'ALL'  ] ; then
     SQOOP="sqoop import --hive-import --connect $DB_URL  \
     --username $DB_USER --password $DB_PASSWORD \
     --table $TBNAME \
     --hive-database $HIVEDB --fields-terminated-by \t -m 1";
elif [ $4 == 'ADD' ] ; then
     CHCL=$5;
     MAX_VAL=$6;
    SQOOP=" sqoop import --incremental append \
 --connect $DB_URL \
 --username $DB_USER --password $DB_PASSWORD --table $TBNAME \
 --target-dir /user/hive/warehouse/$HIVEDB.db/$1 \
 --fields-terminated-by \t  --check-column $CHCL \
 --last-value $MAX_VAL \
 -m 1 "
fi
$SQOOP
